<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>健康档案</title>
	<script type="text/javascript" src="scripts/boot.js"></script>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
     <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
         <table style="width:100%;">
             <tr>
                 <td style="width:100%;">
                 	 <sec:authorize url='/call_health_add.do'>
                     <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
                     </sec:authorize>
                     <sec:authorize url='/call_health_edit.do'>
                     <a class="mini-button" iconCls="icon-edit" onclick="edit()">修改</a>
                     </sec:authorize>
                     <sec:authorize url='/call_health_delete.do'>
                     <a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a>    
                     </sec:authorize>   
                 </td>
                 <td style="white-space:nowrap;">
                     <input id="name" class="mini-textbox" emptyText="请输入名称" style="width:150px;"/>   
                     <a class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
                 </td>
             </tr>
         </table>           
     </div>
     <div class="mini-fit" >
	<div id="treegrid1" class="mini-treegrid" style="width:100%;height:100%;" url="call_health_view.do" showTreeIcon="true" 
		    treeColumn="name" idField="id" parentField="pid" resultAsTree="false"
		    allowDrag="true" allowDrop="true" allowRowSelect="true">
	    <div property="columns">
	   		<div type="indexcolumn"  align="center">序号</div>
	        <div name="name" field="name" width="200" align="center">名称</div>
	        <div name="descpt" field="descpt" width="200" align="center">描述</div>
	    </div>
	</div>
	</div>
<script type="text/javascript">
	mini.parse();
	var grid = mini.get("treegrid1");
	
	//添加节点
	function add(){
		var row = grid.getSelected();
		if(row){
			mini.open({
				url:"call_health_add.do",
				title: "添加节点", width: 245, height: 210,allowResize:false,
				onload: function () {
			 		 var iframe = this.getIFrameEl();
			 		 iframe.contentWindow.SetData(row);
		        },
		        ondestroy: function (action) {
		        	if(action == "succ"){
		        		mini.showMessageBox({
		                    title: "提示",
		                    showModal:false,
		                    iconCls: "mini-messagebox-info",
		                    message: "保存成功！",
		                    timeout: 3000,
		                    x: 'right',
		                    y: 'bottom'
		                });
		        		grid.reload();
		        		grid.expandAll();
		        	}
		        }
		    });
		}else{
			mini.alert("请选择一条数据");
		}
	}
	
	function edit() {
		var row = grid.getSelected();
		if(row){
			mini.open({
				url:"call_health_edit.do",
				title: "修改节点", width: 250, height: 190,allowResize:false,
				onload: function () {
			 		 var iframe = this.getIFrameEl();
			 		 iframe.contentWindow.SetData(row);
		        },
		        ondestroy: function (action) {
		        	if(action == "succ"){
		        		mini.showMessageBox({
		                    title: "提示",
		                    showModal:false,
		                    iconCls: "mini-messagebox-info",
		                    message: "修改成功！",
		                    timeout: 3000,
		                    x: 'right',
		                    y: 'bottom'
		                });
			            grid.reload();
			            grid.expandAll();
		        	}
		        }
		    });
		}else{
			mini.alert("请选择一条数据");
		}
	}
	
	
	function remove() {
		 var row = grid.getSelected();
		 var flag = JudgeHealth();
		 if(flag){
		    if (row) {
		    	mini.confirm("确定删除选中记录？", "删除",
	               function (action) {
	                   if (action == "ok") {
	                   	grid.loading("操作中，请稍后......");
	                       $.post(
	                       	"call_health_delete.do",
	                       	{id:row.id},
	                       	function(data){
	                       		if(data.success){
	                       			mini.showMessageBox({
	                                    title: "提示",
	                                    showModal:false,
	                                    iconCls: "mini-messagebox-info",
	                                    message: "已删除！",
	                                    timeout: 3000,
	                                    x: 'right',
	                                    y: 'bottom'
	                                });
	                       		}else{
	                       			mini.alert("数据错误！");
	                       		}
	                       		grid.reload();
	                       		grid.expandAll();
	                       	},"json");
	                   }
	               });
		    } else {
		    	mini.alert("请选中一条记录");
		    }
		 }else{
			 return false;
		 }
	}
	
	function JudgeHealth(){
		var row = grid.getSelected();
		var flag = true;
		if(row){
	  	    $.ajax({
	  	    	url: "health_judge.do?id="+row.id,
	  	    	dataType: 'json',
	  	        cache: false,
		    	async: false,
	 	        success: function (text) {
	 	            if(text.result){
	 	            	flag = true;
	 	            }else{
	 	            	mini.alert("不允许删除基础类");
	 	            	flag = false;
	 	            }
	 	        }
	  	    });
		}
		    return flag;
	}
	
	function search() {
		var name = mini.get("name").getValue();
		grid.load({name: name});
	}
	
</script>
</body>
</html>
